﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.Message
{
    public partial class MessageCheckedList : System.Web.UI.Page
    {
        IBLL.IBLL_MessageTypeDetail ibllMessage = new BLL.BLL_MessageTypeDetail();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["query"] = URLUtil.GetSuperviseQueryFromURL(Request);
                BindList();
            }
        }
        /// <summary>
        /// 数据绑定
        /// </summary>
        void BindList()
        {

            int t = 0;
            Model.Message message = new HZ.Supervise.Model.Message();

            if (Request.QueryString["type"] != null)
            {
                string typeId = Request.QueryString["type"].ToString();
                message.TypeId = typeId;
            }
            else
            {
                message.TypeId = "1";
            }
            message.Name = txtName.Text.Trim();
            message.CreatTime = txtCreatTime.Text.Trim();
            message.AreaName = txtAreaName.Text.Trim();
            message.HospitalName = txtHospitalName.Text.Trim();
            message.ProductName = txtProductName.Text.Trim();
            message.CompanyName_Jy = txtProductName.Text.Trim();

            message.UserId = CurrentAccount.UserID.ToString();

            gvwMessageCheckedList.DataSource = ibllMessage.GetMessage(message, true, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            gvwMessageCheckedList.DataBind();
            AspNetPager1.RecordCount = t;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelte_Click(object sender, EventArgs e)
        {
            string chkedids = Request.Form["chk"];
            int flag = 1;
            foreach (var item in chkedids.Split(','))
            {
                flag = ibllMessage.DeleteMessage(item);
            }
            if (flag == 1)
            {
                HZ.Web.WebUtil.Alert("删除成功！");
            }
            else
            {
                HZ.Web.WebUtil.Alert("删除失败！");
            }
            BindList();
        }
        protected void gvwMessageCheckedList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //for (int i = 0; i < gvwMessageList.Rows.Count; i++)
            //{
            //    string areaName = ((Label)(gvwMessageList.Rows[i].Cells[2].FindControl("lblAreaName"))).Text.ToString();
            //    ((Label)(gvwMessageList.Rows[i].Cells[2].FindControl("lblAreaName"))).Text = SubStr(areaName, 12);
            //}
        }

        protected void gvwProcureCatalog_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DirectByDetail")
            {
                string sessionid = Guid.NewGuid().ToString();
                SuperviseQuery query = (SuperviseQuery)ViewState["query"];
                try
                {
                    query.MessageId = e.CommandArgument.ToString();
                }
                catch { }
                Session[sessionid] = query;
                string url = "MessageCheckedDetail.aspx";
                Response.Redirect(string.Format("{0}?sessionid={1}", url, sessionid));
            }
        }
        /// <summary>
        /// 字符串截取
        /// </summary>
        /// <param name="sString"></param>
        /// <param name="nLeng"></param>
        /// <returns></returns>
        string SubStr(string sString, int nLeng)
        {
            if (sString.Length <= nLeng)
            {
                return sString;
            }
            string sNewStr = sString.Substring(0, nLeng);
            sNewStr = sNewStr + "...";
            return sNewStr;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindList();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindList();
        }
    }
}
